var ionicApp = angular.module('ionicApp',
        ['ionic','oc.lazyLoad'])

    .constant('ApiEndpoint', {
      url : "../../"

        })
    .run(function ($ionicPlatform) {
        $ionicPlatform.ready(function () {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
                cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                cordova.plugins.Keyboard.disableScroll(true);

            }
            if (window.StatusBar) {
                // org.apache.cordova.statusbar required
                StatusBar.styleDefault();
            }

            //程序启动后退出欢迎界面
            //navigator.splashscreen.hide();

            //锁定屏幕方向
            //screen.lockOrientation('portrait');
        });
    })
    .factory('HttpInterceptor', function () {
        function serializeData(data) {
            if (!angular.isObject(data)) {
                return ((data == null) ? "" : data.toString());
            }
            var buffer = [];
            for (var name in data) {
                if (!data.hasOwnProperty(name)) {
                    continue;
                }
                var value = data[name];
                if (angular.isObject(value)) {
                    value = angular.toJson(value);
                }
                buffer.push(encodeURIComponent(name) + "=" + encodeURIComponent((value == null) ? "" : value));
            }
            // Serialize the buffer and clean it up for transportation.
            var source = buffer.join("&").replace(/%20/g, "+");
            return (source);
        }

        return {
            request: function (config) {
                if (config.data && angular.isObject(config.data)) {
                    if (config.method === 'POST') {
                        config.data = serializeData(config.data);
                    } else if (config.method === 'GET') {
                        config.url += (config.url.indexOf('?') > 0 ? '&' : '?') + serializeData(config.data);
                    }
                }

                return config;
            }
        };
    })

    .config(['$ocLazyLoadProvider', function($ocLazyLoadProvider) {
        $ocLazyLoadProvider.config({
        });
    }])

    .config(function ($stateProvider, $urlRouterProvider, $httpProvider,$ionicConfigProvider) {
        $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
        $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
        $httpProvider.interceptors.push('HttpInterceptor');
        
        $ionicConfigProvider.views.swipeBackEnabled(false);
        $ionicConfigProvider.views.transition('none');
        
        $ionicConfigProvider.platform.ios.tabs.style('standard'); 
        $ionicConfigProvider.platform.ios.tabs.position('bottom');
        $ionicConfigProvider.platform.android.tabs.style('standard');
        $ionicConfigProvider.platform.android.tabs.position('standard');

        $ionicConfigProvider.platform.ios.navBar.alignTitle('center'); 
        $ionicConfigProvider.platform.android.navBar.alignTitle('left');

        $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
        $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');        

        $ionicConfigProvider.platform.ios.views.transition('ios'); 
        $ionicConfigProvider.platform.android.views.transition('android');
        
        $stateProvider
            .state('lineQuery', {
                url: '/lineQuery',
                data: {pageTitle: '测试'},
                templateUrl: 'www/templates/lineQuery.html'
            })
        ;
        $urlRouterProvider.otherwise(function ($injector, $location) {
            $location.path('/lineQuery');
        });

    })
;

